<template>
  <div class="login-container">
    <div class="login">
      <div class="by">
        <div class="meteor" :style="`transform:rotate(${40}deg)`">
          <div class="line" :style="`animationDelay:${1.5}s;width:${2}px;height:${100}px;`"></div>
          <div class="line" :style="`animationDelay:${5}s;width:${1}px;height:${100}px;`"></div>
        </div>
        <div class="meteors" :style="`transform:rotate(${45}deg)`">
          <div class="lines" :style="`animationDelay:${3.5}s;width:${2}px;height:${100}px;`"></div>
        </div>
        <div class="meteort" :style="`transform:rotate(${50}deg)`">
          <div class="linet" :style="`animationDelay:${2.5}s;width:${2}px;height:${100}px;`"></div>
          <div class="linet" :style="`animationDelay:${5}s;width:${1}px;height:${100}px;`"></div>
        </div>

        <div class="login-conter">
          <div class="form">
            <h3>班级管理系统</h3>
            <label for="username">用户名</label>
            <input type="text" placeholder="UserName or Son" id="username" v-model="loginForm.username">

            <label for="password">密码</label>
            <input type="password" placeholder="Password" id="password" @keydown.enter="handleLogin"
              v-model="loginForm.password">
            <button @click="handleLogin">登录</button>
          </div>

        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { validUsername } from '@/utils/validate'

  export default {
    name: 'Login',
    data() {
      const validateUsername = (rule, value, callback) => {
        if (value.length < 5) {
          callback(new Error('Please enter the correct user name'))
        } else {
          callback()
        }
      }
      const validatePassword = (rule, value, callback) => {
        if (value.length < 6) {
          callback(new Error('The password can not be less than 6 digits'))
        } else {
          callback()
        }
      }
      return {
        loginForm: {
          username: '',
          password: ''
        },
        loginRules: {
          username: [{ required: true, trigger: 'blur', validator: validateUsername }],
          password: [{ required: true, trigger: 'blur', validator: validatePassword }]
        },
        loading: false,
        passwordType: 'password',
        redirect: undefined
      }
    },
    watch: {
      $route: {
        handler: function (route) {
          this.redirect = route.query && route.query.redirect
        },
        immediate: true
      }
    },
    methods: {
      showPwd() {
        if (this.passwordType === 'password') {
          this.passwordType = ''
        } else {
          this.passwordType = 'password'
        }
        this.$nextTick(() => {
          this.$refs.password.focus()
        })
      },
      handleLogin() {
        if (this.loginForm.username.trim() == "") {
          this.$message.warning("账号不能为空~")
          return
        }
        if (this.loginForm.password.trim() == "") {
          this.$message.warning("密码不能为空~")
          return
        }
        this.loading = true
        this.$store.dispatch('user/login', this.loginForm).then(() => {
          this.$router.push({ path: this.redirect || '/' })
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      }
    }
  }
</script>
<style lang="scss">
  /* 修复input 背景不协调 和光标变色 */
  /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

  $bg: #283443;
  $light_gray: #fff;
  $cursor: #fff;

  @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
    .login-container .el-input input {
      color: $cursor;
    }
  }

  /* reset element-ui css */
  .login-container {
    .el-input {
      display: inline-block;
      height: 47px;
      width: 85%;

      input {
        background: transparent;
        border: 0px;
        -webkit-appearance: none;
        border-radius: 0px;
        padding: 12px 5px 12px 15px;
        color: $light_gray;
        height: 47px;
        caret-color: $cursor;

        &:-webkit-autofill {
          box-shadow: 0 0 0px 1000px $bg inset !important;
          -webkit-text-fill-color: $cursor !important;
        }
      }
    }

    .el-form-item {
      border: 1px solid rgba(255, 255, 255, 0.1);
      background: rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      color: #454545;
    }
  }
</style>

<style lang="scss" scoped>
  $bg: #2d3a4b;
  $dark_gray: #889aa4;
  $light_gray: #eee;

  .login-container {
    min-height: 100%;
    width: 100%;
    background-color: $bg;
    overflow: hidden;

    .login-form {
      position: relative;
      width: 520px;
      max-width: 100%;
      padding: 160px 35px 0;
      margin: 0 auto;
      overflow: hidden;
    }

    .tips {
      font-size: 14px;
      color: #fff;
      margin-bottom: 10px;

      span {
        &:first-of-type {
          margin-right: 16px;
        }
      }
    }

    .svg-container {
      padding: 6px 5px 6px 15px;
      color: $dark_gray;
      vertical-align: middle;
      width: 30px;
      display: inline-block;
    }

    .title-container {
      position: relative;

      .title {
        font-size: 26px;
        color: $light_gray;
        margin: 0px auto 40px auto;
        text-align: center;
        font-weight: bold;
      }
    }

    .show-pwd {
      position: absolute;
      right: 10px;
      top: 7px;
      font-size: 16px;
      color: $dark_gray;
      cursor: pointer;
      user-select: none;
    }
  }

  .by {
    background: url("https://blog-chen.oss-cn-shanghai.aliyuncs.com/1a55c797db8d42548da8308b74c67aab.png") no-repeat;
    width: 100%;
    min-height: 100vh;
    background-size: 100% 100%;
    background-attachment: fixed;
    position: relative;
    z-index: 10;
  }

  .login-conter {
    width: 1250px;
    margin: 0 auto;
    height: 100vh;
    // border: 1px solid red;
  }

  .form {
    height: 480px;
    width: 400px;
    background-color: rgba(0, 0, 0, 0.13);
    position: absolute;
    transform: translate(-50%, -50%);
    top: 50%;
    left: 50%;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.09);
    box-shadow: 0 0 40px rgba(20, 18, 42, 0.6);
    padding: 50px 35px;
  }

  .form * {
    font-family: 'Poppins', sans-serif;
    color: #ffffff;
    letter-spacing: 0.5px;
    outline: none;
    border: none;
  }

  .form h3 {
    font-size: 32px;
    font-weight: 500;
    line-height: 42px;
    text-align: center;
  }

  label {
    display: block;
    margin-top: 30px;
    font-size: 16px;
    font-weight: 500;
  }

  input {
    display: block;
    height: 50px;
    width: 100%;
    background-color: rgba(255, 255, 255, 0.07);
    border-radius: 3px;
    padding: 0 10px;
    margin-top: 8px;
    font-size: 14px;
    font-weight: 300;
  }

  button {
    margin-top: 50px;
    width: 100%;
    background-color: #ffffff;
    color: #080710 !important;
    padding: 15px 0;
    font-size: 18px;
    font-weight: 600;
    border-radius: 5px;
    cursor: pointer;
  }

  .social {
    margin-top: 30px;
    display: flex;
  }

  .social div {
    background: red;
    width: 150px;
    line-height: 15px;
    border-radius: 3px;
    padding: 5px 10px 10px 5px;
    background-color: rgba(255, 255, 255, 0.27);
    color: #eaf0fb;
    text-align: center;
  }

  .social div:hover {
    background-color: rgba(255, 255, 255, 0.47);
  }

  .social .co {
    margin-left: 25px;
  }

  .social i {
    margin-right: 4px;
  }

  ::placeholder {
    color: #e5e5e5;
  }

  .fb {
    margin-left: 71px;
  }



  .meteor {
    width: 2px;
    height: 200px;
    position: relative;
    margin: 0 auto;
    float: left;
    margin-left: 300px;

    .line {
      animation: meteoring 6s infinite linear;
      position: absolute;
      width: 2px;
      height: 200px;
      background: linear-gradient(to top,
          rgb(2, 161, 195, 1),
          rgba(11, 36, 66, 0.1));
      border-radius: 2px;
      box-shadow: 0px 10px 20px 0px #02a1c3;
      opacity: 0;

      &::before {
        width: 2px;
        height: 2px;
        content: "";
        position: absolute;
        bottom: 0px;
        left: 0px;
        border-radius: 50%;
        background: #00d0ff;
        box-shadow: 0px 0px 12px 5px #00d0ff;
      }
    }
  }


  .meteors {
    width: 2px;
    height: 200px;
    position: relative;
    margin: 0 auto;
    float: left;
    margin-left: 500px;



    .lines {
      animation: meteoring 6s infinite linear;
      position: absolute;
      width: 2px;
      height: 200px;
      background: linear-gradient(to top,
          rgb(2, 161, 195, 1),
          rgba(11, 36, 66, 0.1));
      border-radius: 2px;
      box-shadow: 0px 10px 20px 0px #02a1c3;
      opacity: 0;

      &::before {
        width: 2px;
        height: 2px;
        content: "";
        position: absolute;
        bottom: 0px;
        left: 0px;
        border-radius: 50%;
        background: #00d0ff;
        box-shadow: 0px 0px 12px 5px #00d0ff;
      }
    }
  }


  .meteort {
    width: 2px;
    height: 200px;
    position: relative;
    float: right;
    margin-right: 300px;

    // overflow: hidden;
    .linet {
      animation: meteoring 6s infinite linear;
      position: absolute;
      width: 2px;
      height: 200px;
      background: linear-gradient(to top,
          rgb(2, 161, 195, 1),
          rgba(11, 36, 66, 0.1));
      border-radius: 2px;
      box-shadow: 0px 10px 20px 0px #02a1c3;
      opacity: 0;

      &::before {
        width: 2px;
        height: 2px;
        content: "";
        position: absolute;
        bottom: 0px;
        left: 0px;
        border-radius: 50%;
        background: #00d0ff;
        box-shadow: 0px 0px 12px 5px #00d0ff;
      }
    }
  }

  @keyframes meteoring {
    0% {
      opacity: 0;
      top: -250px;
    }

    25% {
      opacity: 0.5;
      top: 0px;
    }

    50% {
      opacity: 0.8;
      top: 250px;
    }

    75% {
      opacity: 1;
      top: 500px;
    }

    100% {
      opacity: 0;
      top: 750px;
    }
  }
</style>